package cn.mesmile.socket.grps;

import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author
 */
public class GPRSTest {

    static int port = 8070;

    public static void main(String[] args) {
        try {
            ServerSocket server = new ServerSocket(port);
            while (true) {
                // 获得客户端连接,阻塞式方法
                final Socket client = server.accept();
                new Thread(() -> {
                    InputStream inputStream = null;
                    try {
                        inputStream = client.getInputStream();
                        byte[] buffer = new byte[1024];
                        int len = -1;
                        while ((len = inputStream.read(buffer)) != -1) {
                            String result = new String(buffer, 0, len);
                            System.out.println("result = " + result);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }).start();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}